package io.github.junxworks.qt.modules.data.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.github.junxworks.qt.modules.data.mapper.DataStoreMapper;
import io.github.junxworks.qt.modules.data.service.DataStoreService;

@Service
public class DataStoreServiceImpl implements DataStoreService {
	@Autowired
	private DataStoreMapper mapper;

	@Override
	public int insertBatch(List<?> objs) {
		return insertBatch(objs, 100);
	}

	@Override
	public int insertBatch(List<?> objs, int batchSize) {
		for (int page = 1, index = 0, len = objs.size(); index < len; page++) {
			int toIndex = page * batchSize;
			if (toIndex >= len) {
				toIndex = len;
			}
			List<?> subList = objs.subList(index, toIndex);
			mapper.insertBatch(subList);
			index = toIndex;
		}
		return objs.size();
	}

	@Override
	public int insert(Object macd) {
		return mapper.insertWithoutNull(macd);
	}

}
